<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>1</title>
    <style>
      label {
        display: block;
        padding: 6px;
      }
    </style>
    <script>
      function onRead() {
        var cstr = document.cookie;
        console.log(666.0005, cstr);
        //-----------------------
        /*console.log(
          666.00055,
          "{" + cstr.replace(/; /g, ",").replace(/=/g, ":") + "}"
        );
        var allobj = JSON.parse(
          '{"' + cstr.replaceAll("; ", ',"').replaceAll("=", '":') + "}"
        );
        console.log(666.00066, allobj, allobj.user);*/
        //---------------------

        var cindexof = cstr.indexOf("user=");
        var csubstring = cstr.substring(cindexof + 5);
        console.log(666.001, cindexof, csubstring);

        var cindexof2 = csubstring.indexOf("; ");
        if (cindexof2 > -1) {
          csubstring = csubstring.substring(0, cindexof2);
        }
        console.log(666.002, cindexof2, csubstring);

        var objectdata = JSON.parse(csubstring);
        for (item in objectdata) {
          if (item === "xingbie") {
            if (objectdata.xingbie === 1) {
              document.getElementById("xingbie1").checked = true;
            } else {
              document.getElementById("xingbie2").checked = true;
            }
          } else {
            // console.log(666.333,item,objectdata[item])
            document.getElementById(item).value = objectdata[item];
          }
        }

        console.log(666.777, cstr, cindexof, csubstring, objectdata);
      }
    
        var objectdata = {
          xingming: "",
          shengri: "",
          shengrinian: "",
          shengriyue: "",
          shengriri: "",
          jianjie: "",
        };
        for (item in objectdata) {
          objectdata[item] = document.getElementById(item).value;
        }
        var xingbieobj = {
          xingbie1: "",
          xingbie2: "",
        };

        for (item in xingbieobj) {
          if (document.getElementById(item).checked === true) {
            // objectdata.xingbie = item === "xingbie1" ? 1 : 2;
            if (item === "xingbie1") {
              objectdata.xingbie = 1;
            } else {
              objectdata.xingbie = 2;
            }
          }
          console.log(
            666.003,
            document.getElementById(item).checked,
            document.getElementById(item).value
          );
        }
        // console.log(666.005,objectdata,JSON.stringify(objectdata))
        document.cookie = "user=" + JSON.stringify(objectdata);
        alert();
      
    </script>
  </head>
  <body>
    <label>姓名:<input type="text" id="xingming" /></label>
    
      性别：

      <input type="radio" name="xingbie" id="xingbie1" value="1" />男
      <input type="radio" name="xingbie" id="xingbie2" value="2" />女
    </label>
    <label>
      简介(不多于100字)
      <input
        type="text"
        id="jianjie"
        value=""
        size="50"
        maxlength="100"
        onchange="document.getElementById('shuzi').value=this.value.length"
        oninput="document.getElementById('shuzi').value=this.value.length"
      />
      <input type="text" id="shuzi" />
    </label>
    <label>
      <a href="http://127.0.0.1:5500/%E7%BB%BC%E5%90%88/%E8%AE%A1%E7%AE%97%E5%A4%A7%E9%A2%98%E9%A1%B5-2.html"><input type="button" onclick="onRead()" value="开始答题" /></a> 
    </label>
  </body>
</html>
